<template>
	<div>
		<NavigationBar :title-text="classify" :custom-back-func="handleNavigateBack" />
		<Message ref="message" />
		<Loading ref="loading" fullscreen />

		<div class="doctor-depart-container w-full pt-160rpx pb-0rpx px-0rpx bg-hex-a0cfff overflow-x-hidden">
			<div class="w-full min-h-90vh flex-column bg-hex-f4f4f5 overflow-x-hidden">
				<div class="p-30rpx" v-if="departmentinfoList.length>0">
					<div
						class="order-item w-full mb-20rpx p-30rpx flex-column bg-white rounded-xl"
						v-for="item in departmentinfoList"
						:key="item.id"
						@click="gotoDetail(item.jobnumber,item.classify)"
					>
						<div class="w-full flex items-center justify-between">
							<div class="w-100rpx h-100rpx">
								<image class="w-full h-full" :src="item.img" mode="aspectFill" />
							</div>
							<div class="flex-grow-1 text-center font-bold">{{ item.userName }}</div>
						</div>
						<div class="w-full flex items-center justify-between mt-10rpx">
							<div>科室：{{ item.name }}</div>
						</div>
					</div>
				</div>
                <div v-else class="h-500rpx w-full flex items-center justify-center">
                     <div class="text-30rpx">暂无医生信息</div>
                </div>
			</div>
		</div>
	</div>
</template>

<script setup lang="ts">
import Message from '@/components/message/src/message.vue';
import type { MessageMethod } from '@/components/message';
import Loading from '@/components/loading/src/loading.vue';
import type { LoadingMethod } from '@/components/loading';
import NavigationBar from '@/components/navigation-bar/src/navigation-bar.vue';
import { gotoPage } from '@/common/utils';
import { useUserStore } from '@/store';
import { userApi, serveApi } from '@/service/api';

const userStore = useUserStore();

const message = ref<InstanceType<typeof Message> & MessageMethod>(null);
const loading = ref<InstanceType<typeof Loading> & LoadingMethod>(null);
const classify = ref<string>('');
const role = ref<string>('');
const departmentinfoList = ref([]);
// 初始化
const init = async () => {
	const res = await serveApi.getDepartmentInfo({ searchKey: classify.value });
	console.log(res.data?.result);
	departmentinfoList.value = res.data?.result;
};
// 跳转预约页面
const gotoDetail = useThrottleFn(
	(jobnumber,classify): void => {
		gotoPage(`/pages/depart-info/depart-info?jobnumber=${jobnumber}&classify=${classify}`)
	},
	2000,
	false,
	true
);

// 返回上一页
const handleNavigateBack = (): void => {
	uni.navigateBack({
		delta: 2,
	});
};
onLoad((option) => {
	if (option) {
		classify.value = option.classify;
		console.log(classify.value);
		init();
		return;
	}
	nextTick(() => uni.navigateBack());
});
onShow(() => {});
</script>

<style scoped lang="scss">
@import 'doctor-depart';
</style>
